package okw.gui;

import java.util.ArrayList;

import okw.network.ConnectionO;
import okw.network.StanO;
import okw.network.Terminal;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;

public class TestWindow {

	// TODO: mozna zmienic na prawodziwy test, ulepszyc
	public TestWindow(Shell parent, ConnectionO cm, StanO stanO){
		Shell shell = new Shell(parent);
		Group dane = new Group(shell, SWT.BORDER);
		ArrayList<String> notConnected = new ArrayList<String>();
		
		// tutaj bedziemy korzystac z connectionTest kiedys.
		
		for(Terminal t: cm.getTerminale()){
			if(t.getStan() == null || !t.getStan().isPolaczenie())
				notConnected.add(t.getName());
		}
		if(notConnected.size()==0){
			Label label = new Label(dane, SWT.CENTER);
			label.setText("Wszystkie terminale podlaczone poprawnie");
			label.setLocation(5, 40);
			label.setSize(150,50);
			label.pack();
		} else {
			Label label = new Label(dane, SWT.CENTER);
			label.setText("Niepodlaczone terminale:");
			label.setLocation(5, 5);
			label.pack();
			Table terminals = new Table(dane, SWT.SINGLE);
			terminals.setSize(150,70);
			terminals.setLocation(5,25);
			for(String s: notConnected){
				TableItem ti = new TableItem(terminals, SWT.NONE);
				ti.setText(s);
			}
		}
		
		Label label = new Label(dane, SWT.CENTER);
		label.setText((stanO.isPolaczenie() ? "Centrala podlaczona poprawnie" : "Brak polaczenia z centrala"));
		label.setLocation(10, 100);
		label.setSize(150,50);
			
		dane.pack();
		shell.pack();
		MainWindowO.center(shell);
		shell.open();
	}
}
